#[derive(Debug, Clone)]
struct Node<T: Ord + Clone> {
    value: T,
    next: Option<Box<Node<T>>>,
}

#[derive(Debug, Clone)]
struct List<T: Ord + Clone> {
    root: Option<Box<Node<T>>>,
}

impl<T: Ord + std::fmt::Display + Clone> List<T> {
    fn new() -> Self {
        Self {
            root: None,
        }
    }
    fn show(self) {
        let mut c = self.root;
        loop {
            match c {
                None => {
                    println!("will exit");
                    break;
                }
                Some(n) => {
                    n.clone().show();
                    c = n.next
                }
            }
        }
    }
    fn insert(mut self, mut b: Box<Node<T>>) -> Self {
        b.next = self.root;
        self.root = Some(b);
        self
    }
}

impl<T: Ord + std::fmt::Display + Clone> Node<T> {
    fn new(v: T) -> Self {
        Self { value: v, next: None }
    }
    fn show(self) {
        println!("node with value={} {}", self.value,
                 if self.next.is_none() {"has not next -|"} else {"has next ->"});
    }
}


fn main() {
    let mut list: List<i32> = List::new();
    list = list.insert(Box::new(Node::new(1)))
        .insert(Box::new(Node::new(2)))
        .insert(Box::new(Node::new(3)));
    println!("3::{:?}", list);
    list.show();
}